<?php if (!defined('BASE')) {die('No direct file access.');}

//********************************
//	File:		config.php
//	Author:		Philip Pryce
//	Date:		20th July 2008
//	Comments:	A library for loading and fetching variables kept in configuration files.
//********************************

class Config {
	
	var $cached = array();
	var $loaded = array();
	
	function __construct () {
		
		$this->load('default');
		
	}
	
	function load ($file) {
		
		if (file_exists(APP . 'config/' . $file . '.php')) {
			$config = array(); // stop notices for incase the config file is blank.
			// include the config file
			include_once(APP . 'config/' . $file . '.php');
			// merge the config file into the configuration tree.
			$this->cached = array_merge($config, $this->cached);
			// add this configuration file to the loaded files list.
			$this->loaded[] = $file;
			return $this->cached;
		}
		else {
			displayError(ERROR_FATAL, 'Config->load', 'Configuration file "' . $file . '" doesnt exist.');
			return false;
		}
		
	}
	
	function get ($index) {
		if (array_key_exists($index, $this->cached)) {
			return $this->cached[$index];
		}
		else {return false;}
	}
	
	function remove ($index) {
		if (array_key_exists($index, $this->cached)) {
			unset($this->cached[$index]);
		}
		else {return false;}
	}
	
}

?>